package com.sl.hx.shop.ui.home.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.DynamicDrawableSpan;
import android.text.style.StrikethroughSpan;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sl.hx.shop.R;
import com.sl.hx.shop.bean.ProductList;
import com.sl.hx.shop.bean.RelationBean;
import com.sl.hx.shop.utils.CornerTransform;
import com.sl.hx.shop.utils.ScreenUtil;

import java.util.List;


public class RelationListAdapter extends BaseQuickAdapter<RelationBean, BaseViewHolder> {


    public RelationListAdapter(@Nullable List<RelationBean> data) {
        super(R.layout.item_goods, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final RelationBean item) {

        CornerTransform transformation = new CornerTransform(mContext, ScreenUtil.dp2px(mContext, 8));
        //只是绘制左上角和右上角圆角
        transformation.setExceptCorner(false, false, true, true);

        ImageView pic = helper.getView(R.id.pict);
        Glide.with(mContext).load(item.getPict_url()).apply(RequestOptions.bitmapTransform(transformation)).into(pic);

        helper.setText(R.id.zk_final_price,item.getZk_final_price().substring(0,item.getZk_final_price().lastIndexOf('.')))
                .setText(R.id.volume,item.getVolume()+"人已付款");

        //标题前加淘宝图片
        TextView title = helper.getView(R.id.GoodsName);
        SpannableStringBuilder stringBuilder=new SpannableStringBuilder(" "+item.getTitle());
        DynamicDrawableSpan ab=new DynamicDrawableSpan() {
            @Override
            public Drawable getDrawable() {
                if (item.getUser_type()==0){
                    Drawable drawable = mContext.getResources().getDrawable(R.drawable.taobao);
                    drawable.setBounds(0,0,70,36);
                    return drawable;
                }else {
                    Drawable drawable = mContext.getResources().getDrawable(R.drawable.tianmao);
                    drawable.setBounds(0,0,70,36);
                    return drawable;
                }
            }
        };
        stringBuilder.setSpan(ab,0,1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        title.setText(stringBuilder);

        //原价设置删除线
        TextView reserve_price = helper.getView(R.id.reserve_price);
        SpannableStringBuilder spannableString = new SpannableStringBuilder("￥"+item.getReserve_price().substring(0,item.getReserve_price().lastIndexOf('.')));
        StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
        spannableString.setSpan(strikethroughSpan, 0, ("￥"+item.getReserve_price().substring(0,item.getReserve_price().lastIndexOf('.'))).length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        reserve_price.setText(spannableString);

    }

}
